﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace Dxr.Web.Host
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            Zongsoft.Plugins.Application.Started += Application_Started;
            Zongsoft.Plugins.Application.Start(Zongsoft.Plugins.Web.ApplicationContext.Current, null);
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {
            Zongsoft.Plugins.Application.Exit();
        }

        private void Application_Started(object sender, Zongsoft.Plugins.ApplicationEventArgs e)
        {
            var context = Zongsoft.Plugins.Application.Context;

            //将应用上下文对象保存到ASP.NET的全局应用缓存容器中
            Application["ApplicationContext"] = context;

            //注销插件应用的启动完成事件的通知
            Zongsoft.Plugins.Application.Started -= Application_Started;
        }
    }
}